/******************** 
	作用:编辑账号
	作者:蔡俊雄
	版本:V1.0
	时间:2015-08-01
********************/
$(function() {
	


// add
//-----------------选择权限-----------------
var character_limit = {
	data:[],
	initCheckbox_ : function(parentCheck, name) {
		var check_parent = '#' + parentCheck;
		$(check_parent).on('click', function(e) {
			$('input[type=checkbox][name=' + name + ']').prop('checked', $(this).prop('checked'));
			character_limit.updateCheckIds(name);
		})
		$('input[type=checkbox][name='+ name +']').on('click', function(e) {
			character_limit.updateCheckIds(name);	
			var checkbox = $('input[name=' + name + ']');
			var checkedbox = $('input[name=' + name + ']:checked');
			var uncheckedbox = checkbox.length - checkedbox.length;

			if (uncheckedbox) {
				$(this).closest('.form-group').find('.item >input').prop('checked', false);
			} else {
				$(this).closest('.item').find('input').attr('checked', 'checked');
			}
		})
	},
	updateCheckIds : function(name) {
		character_limit.data[name] = [];
		character_limit.data['characterName'] = $('#sceneName').val();
		var checkedbox = $('input[name=' + name + ']:checked');
		$.each(checkedbox, function(index, value) {
			(character_limit.data[name]).push($(value).val());
			// $(this).closest('label').siblings().prop('checked', !$(this).prop('checked'))
		})
	}
}
character_limit.initCheckbox_('smgr-check-all', 'spgl');
character_limit.initCheckbox_('mdmgr-check-all', 'mdgl');
character_limit.initCheckbox_('ddmgr-check-all', 'ddgl');
character_limit.initCheckbox_('xsmgr-check-all', 'xsgl');
character_limit.initCheckbox_('dnmgr-check-all', 'ddgl');
character_limit.initCheckbox_('mdmgr-check-all', 'mdgl');
character_limit.initCheckbox_('xtmgr-check-all', 'xtmgr');
character_limit.initCheckbox_('cwjs-check-all', 'cwjs');
$('#submitBtn').on('click', function(e) {
	General.stopEvent(e);
	console.log(character_limit.data);
})
});